Imports System.Diagnostics.Process
Imports System.Threading
Public Class F_ProgramMaster
    Dim WithEvents SBO_Application As SAPbouiCOM.Application
    Dim Ocompany As SAPbobsCOM.Company
    Sub New(ByVal ocompany1 As SAPbobsCOM.Company, ByVal sbo_application1 As SAPbouiCOM.Application)
        SBO_Application = sbo_application1
        Ocompany = ocompany1
    End Sub
    Public Sub ProgramMaster_bind(ByVal oform As SAPbouiCOM.Form)
        Try

            CFL_BP_Employee(oform, SBO_Application)
            oCombo = oform.Items.Item("6").Specific
            ComboLoad_Program(oform, oCombo)
            oEdit = oform.Items.Item("22").Specific
            oEdit.String = Format(Now.Date, "dd/MM/yy")
            oEdit = oform.Items.Item("8").Specific
            oEdit.String = Format(Now.Date, "dd/MM/yy")
            oEdit = oform.Items.Item("24").Specific
            oEdit.String = "Open"
            oCombo = oform.Items.Item("18").Specific
            oCombo.Select(0, SAPbouiCOM.BoSearchKey.psk_Index)
            oEdit = oform.Items.Item("14").Specific
            oEdit.ChooseFromListUID = "CFLEMP"
            oEdit.ChooseFromListAlias = "empID"

            oform.DataBrowser.BrowseBy = "1000002"
        Catch ex As Exception
            SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
        End Try

    End Sub
    Private Sub ComboLoad_Program(ByRef Oform As SAPbouiCOM.Form, ByRef oCombo As SAPbouiCOM.ComboBox)
        Try
            oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
            oRecordSet.DoQuery("SELECT T0.Code, T0.Name FROM [dbo].[@AI_PROGRAM]  T0")
            Dim it As Integer = 1
            For it = oCombo.ValidValues.Count - 1 To 0 Step -1
                oCombo.ValidValues.Remove(it, SAPbouiCOM.BoSearchKey.psk_Index)
            Next
            Do While Not oRecordSet.EoF
                oCombo.ValidValues.Add(oRecordSet.Fields.Item(0).Value, oRecordSet.Fields.Item(1).Value)
                oRecordSet.MoveNext()
            Loop
            oRecordSet = Nothing
            GC.Collect()
        Catch ex As Exception
            SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
        End Try
    End Sub



    Private Sub SBO_Application_ItemEvent(ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent, ByRef BubbleEvent As Boolean) Handles SBO_Application.ItemEvent

        'Choose From List
        Try
            If pVal.FormUID = "AI_PROGMASTER" Then
                oForm = SBO_Application.Forms.Item("AI_PROGMASTER")
                If pVal.EventType = SAPbouiCOM.BoEventTypes.et_CHOOSE_FROM_LIST Then
                    Dim oCFLEvento As SAPbouiCOM.IChooseFromListEvent
                    oCFLEvento = pVal
                    Dim sCFL_ID As String
                    sCFL_ID = oCFLEvento.ChooseFromListUID
                    oForm = SBO_Application.Forms.Item(FormUID)
                    Dim oCFL As SAPbouiCOM.ChooseFromList
                    oCFL = oForm.ChooseFromLists.Item(sCFL_ID)
                    Try
                        If oCFLEvento.BeforeAction = False Then
                            Dim oDataTable As SAPbouiCOM.DataTable
                            oDataTable = oCFLEvento.SelectedObjects
                            If pVal.ItemUID = "14" Then
                                'oEdit = oForm.Items.Item("26").Specific
                                'oEdit.String = oDataTable.GetValue("lastName", 0) & " " & oDataTable.GetValue("firstName", 0)
                                Try
                                    oEdit = oForm.Items.Item("14").Specific
                                    oEdit.String = oDataTable.GetValue("empID", 0)
                                Catch ex As Exception
                                End Try

                            End If
                        End If
                    Catch ex As Exception
                        '' SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                    End Try
                End If
            End If
            '--------------------
        Catch ex As Exception
        End Try
        '======================================================

        Try
            '-------------------End Choose From List-----------
            If pVal.FormUID = "AI_PROGMASTER" And pVal.InnerEvent = False Then
                oForm = SBO_Application.Forms.Item("AI_PROGMASTER")
                If pVal.Before_Action = False Then
                    Select Case pVal.EventType
                        Case SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED
                            If pVal.FormMode = SAPbouiCOM.BoFormMode.fm_ADD_MODE Then
                                If pVal.ItemUID = "1" Then
                                    oEdit = oForm.Items.Item("22").Specific
                                    oEdit.String = Format(Now.Date, "dd/MM/yy")
                                    oEdit = oForm.Items.Item("8").Specific
                                    oEdit.String = Format(Now.Date, "dd/MM/yy")
                                    oEdit = oForm.Items.Item("24").Specific
                                    oEdit.String = "Open"
                                    oCombo = oForm.Items.Item("18").Specific
                                    oCombo.Select(0, SAPbouiCOM.BoSearchKey.psk_Index)
                                End If
                            End If

                        Case SAPbouiCOM.BoEventTypes.et_COMBO_SELECT
                            If pVal.ItemUID = "6" Then
                                oCombo = oForm.Items.Item("6").Specific
                                oEdit = oForm.Items.Item("4").Specific
                                oEdit.String = oCombo.Selected.Description
                            End If

                    End Select
                ElseIf pVal.Before_Action = True Then
                    Select Case pVal.EventType
                        Case SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED
                            If pVal.FormMode = SAPbouiCOM.BoFormMode.fm_ADD_MODE Or pVal.FormMode = SAPbouiCOM.BoFormMode.fm_UPDATE_MODE Then
                                If pVal.ItemUID = "1" Then
                                    oEdit = oForm.Items.Item("4").Specific
                                    If oEdit.String = "" Then
                                        SBO_Application.StatusBar.SetText("Select Program Name", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                        BubbleEvent = False
                                        Exit Sub
                                    End If
                                    oEdit = oForm.Items.Item("8").Specific
                                    If oEdit.String = "" Then
                                        SBO_Application.StatusBar.SetText("Select Program Date", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                        BubbleEvent = False
                                        Exit Sub
                                    End If
                                    oEdit = oForm.Items.Item("22").Specific
                                    If oEdit.String = "" Then
                                        SBO_Application.StatusBar.SetText("Select Document Date", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                        BubbleEvent = False
                                        Exit Sub
                                    End If
                                    Try
                                        oCombo = oForm.Items.Item("6").Specific
                                        If oCombo.Selected.Value = "" Then
                                            SBO_Application.StatusBar.SetText("Select Program Code", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                            BubbleEvent = False
                                            Exit Sub
                                        End If
                                    Catch ex As Exception
                                        SBO_Application.StatusBar.SetText("Select Program Code", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                        BubbleEvent = False
                                        Exit Sub
                                    End Try
                                End If
                            End If
                    End Select
                End If
            End If
        Catch ex As Exception
            ' SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
        End Try


    End Sub
End Class
